﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Equipment.aspx.cs" Inherits="WebForms_Equipment" %>

<asp:Content ID="Content2" ContentPlaceHolderID="FeaturedContent" runat="Server">
    <section class="featured">
        <div class="content-wrapper" dir="rtl">
            تجهیزات
        </div>
    </section>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="Server">
    <script lang="jv" type="text/javascript">
        function SelectItem(sender, e) {
            e.IsValid = (e.Value != '0');
        }
    </script>

    <asp:MultiView ID="MultiView1" runat="server">
        <asp:View ID="ShowView" runat="server">
            <div dir="rtl" style="width: 100%;">
                <asp:ImageButton ID="NewImageButton" runat="server" OnClick="NewImageButton_Click" SkinID="DatabaseAddButton" />
                <asp:ImageButton ID="SearchImageButton" runat="server" OnClick="SearchImageButton_Click"
                    SkinID="SearchButton" />
                <asp:ImageButton ID="ClearImageButton" runat="server" OnClick="ClearImageButton_Click"
                    OnClientClick="return false;" SkinID="ClearButton" />
                <br />
                <asp:Label ID="EquipmentNameLabel" runat="server" Text="نام تجهیزات:" SkinID="Caption" CssClass="lable"></asp:Label>
                <asp:TextBox ID="EquipmentNameTextBox" runat="server" SkinID="TextBox"></asp:TextBox>
                <asp:Label ID="EquipmentCodeLabel" runat="server" Text="کد شناسایی:" SkinID="Caption" CssClass="lable"></asp:Label>
                <asp:TextBox ID="EquipmentCodeTextBox" runat="server" SkinID="TextBox"></asp:TextBox>
                <asp:Label ID="SizePageLabel" runat="server" Text="سایز صفحه:" SkinID="Caption" CssClass="lable"></asp:Label>
                <asp:DropDownList ID="PageSizeDropDownList" SkinID="SearchDropDownList" runat="server">
                    <asp:ListItem Selected="True" Value="5">[پیش فرض]</asp:ListItem>
                    <asp:ListItem Value="5">5 رکورد</asp:ListItem>
                    <asp:ListItem Value="10">10 رکورد</asp:ListItem>
                    <asp:ListItem Value="15">15 رکورد</asp:ListItem>
                    <asp:ListItem Value="20">20 رکورد</asp:ListItem>
                    <asp:ListItem Value="25">25 رکورد</asp:ListItem>
                    <asp:ListItem Value="1000000">تمام رکورد ها</asp:ListItem>
                </asp:DropDownList>
            </div>
            <br />
            <div style="float: right; width: 90%; vertical-align: top;" dir="rtl" class="gvclass">
                <asp:GridView ID="EquipmentGridView" runat="server" AllowPaging="True" AllowSorting="True"
                    DataKeyNames="PkEquipmentID" DataSourceID="EquipmentEntityDataSource"
                    Width="100%" AutoGenerateColumns="False" OnSelectedIndexChanged="EquipmentGridView_SelectedIndexChanged">
                    <Columns>
                        <asp:TemplateField>
                            <ItemTemplate>
                                <asp:ImageButton ID="SelectImageButton" runat="server" CommandName="Select" SkinID="SelectButton" />
                            </ItemTemplate>
                            <ItemStyle Width="25px" />
                        </asp:TemplateField>
                        <asp:BoundField DataField="PkEquipmentID" HeaderText="PkEquipmentID" ReadOnly="True" SortExpression="PkEquipmentID" Visible="False" />
                        <asp:BoundField DataField="EquipmentName" HeaderText="نام تجهیزات" SortExpression="EquipmentName">
                            <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" />
                            <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" />
                        </asp:BoundField>
                        <asp:BoundField DataField="EquipmentCode" HeaderText="کد شناسایی تجهیزات" SortExpression="EquipmentCode">
                            <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="200px" />
                            <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="200px" />
                        </asp:BoundField>
                        <asp:BoundField DataField="ElectricUsage" HeaderText="میزان برق مصرفی" SortExpression="ElectricUsage">
                            <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" />
                            <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" />
                        </asp:BoundField>
                    </Columns>
                </asp:GridView>

            </div>
        </asp:View>
        <asp:View ID="EditView" runat="server">
            <div dir="rtl" style="width: 20%; float: right">&nbsp;</div>
            <div dir="rtl" style="width: 60%; float: right">
                <asp:FormView ID="EquipmentFormView" runat="server" DataSourceID="EquipmentEntityDataSource" DataKeyNames="PkEquipmentID" DefaultMode="Insert" Width="100%">
                    <EditItemTemplate>
                        <asp:Label ID="EquipmentNameLabel" runat="server" Text="نام تجهیزات:"  CssClass="lable"></asp:Label>
                        <asp:TextBox ID="EquipmentNameTextBox" runat="server" Text='<%# Bind("EquipmentName") %>' />
                        <asp:RequiredFieldValidator ID="EquipmentNameRequiredFieldValidator" runat="server" ControlToValidate="EquipmentNameTextBox"
                            Display="Dynamic" ErrorMessage="*" ValidationGroup="Update"></asp:RequiredFieldValidator>
                        <br />
                        <asp:Label ID="EquipmentCodeLabel" runat="server" Text="کد شناسایی تجهیزات:"  CssClass="lable"></asp:Label>
                        <asp:TextBox ID="EquipmentCodeTextBox" runat="server" Text='<%# Bind("EquipmentCode") %>' />
                        <br />
                        <asp:Label ID="ElectricUsageLabel" runat="server" Text="میزان برق مصرفی:"  CssClass="lable"></asp:Label>
                        <asp:TextBox ID="ElectricUsageTextBox" runat="server" Text='<%# Bind("ElectricUsage") %>' />
                        <asp:Label ID="ElectricUsageLabel1" runat="server" Text="کیلو وات" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:RequiredFieldValidator ID="ElectricUsageRequiredFieldValidator" runat="server" ControlToValidate="ElectricUsageTextBox"
                            Display="Dynamic" ErrorMessage="*" ValidationGroup="Update"></asp:RequiredFieldValidator>
                        <asp:RangeValidator ID="ElectricUsageRangeValidator" runat="server" ControlToValidate="ElectricUsageTextBox"
                            ErrorMessage="مقدار وارد شده باید عدد باشد" Display="Dynamic"  Type="Double" ValidationGroup="Update" MinimumValue="0" MaximumValue="2147483647"></asp:RangeValidator>
                        <br />
                        <asp:Label ID="DescriptionLabel" runat="server" Text="توضیحات:"  CssClass="lable"></asp:Label>
                        <asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>' TextMode="MultiLine" Width="300px" />
                        <br />
                        <div style="float: left; padding: 10px;">
                            <asp:LinkButton ID="DeleteLinkButton" runat="server" CausesValidation="False" CommandName="Delete" CssClass="button"
                                OnClientClick="if (!confirm('آيا از حذف مطمئن هستيد؟')) return false;" Text="حذف" />

                            <asp:LinkButton ID="UpdateLinkButton" runat="server" CommandName="Update"
                                ValidationGroup="Update" OnClientClick="if (!confirm('آيا از اعمال تغییرات مطمئن هستيد؟')) return false;" Text="ویرایش" CssClass="button" />
                            <asp:LinkButton ID="CancelLinkButton" runat="server" CommandName="Cancel" Text="انصراف" CssClass="button" />
                        </div>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:Label ID="EquipmentNameLabel" runat="server" Text="نام تجهیزات:" CssClass="lable"></asp:Label>
                        <asp:TextBox ID="EquipmentNameTextBox" runat="server" Text='<%# Bind("EquipmentName") %>' />
                        <asp:RequiredFieldValidator ID="EquipmentNameRequiredFieldValidator" runat="server" ControlToValidate="EquipmentNameTextBox"
                            Display="Dynamic" ErrorMessage="*" ValidationGroup="Insert"></asp:RequiredFieldValidator>
                        <br />
                        <asp:Label ID="EquipmentCodeLabel" runat="server" Text="کد شناسایی تجهیزات:"  CssClass="lable"></asp:Label>
                        <asp:TextBox ID="EquipmentCodeTextBox" runat="server" Text='<%# Bind("EquipmentCode") %>' />
                        <br />
                        <asp:Label ID="ElectricUsageLabel" runat="server" Text="میزان برق مصرفی:"  CssClass="lable"></asp:Label>
                        <asp:TextBox ID="ElectricUsageTextBox" runat="server" Text='<%# Bind("ElectricUsage") %>' />
                        <asp:Label ID="ElectricUsageLabel1" runat="server" Text="کیلو وات" SkinID="Caption" CssClass="lable"></asp:Label>
                        <asp:RequiredFieldValidator ID="ElectricUsageRequiredFieldValidator" runat="server" ControlToValidate="ElectricUsageTextBox"
                            Display="Dynamic" ErrorMessage="*" ValidationGroup="Insert"></asp:RequiredFieldValidator>
                        <asp:RangeValidator ID="ElectricUsageRangeValidator" runat="server" ControlToValidate="ElectricUsageTextBox"
                            ErrorMessage="مقدار وارد شده باید عدد باشد" Display="Dynamic" Type="Double" ValidationGroup="Insert" MinimumValue="0" MaximumValue="2147483647"></asp:RangeValidator>
                        <br />
                        <asp:Label ID="DescriptionLabel" runat="server" Text="توضیحات:"  CssClass="lable"></asp:Label>
                        <asp:TextBox ID="DescriptionTextBox" runat="server" Text='<%# Bind("Description") %>' TextMode="MultiLine" Width="300px" />
                        <br />
                        <div style="float: left; padding: 10px;">
                            <asp:LinkButton ID="InsertLinkButton" runat="server" CommandName="Insert" Text="ایجاد" CssClass="button"
                                ValidationGroup="Insert" />
                            <asp:LinkButton ID="CancelLinkButton" runat="server" CommandName="Cancel" Text="انصراف" CssClass="button" />
                        </div>
                    </InsertItemTemplate>
                </asp:FormView>
            </div>
        </asp:View>
    </asp:MultiView>
    <asp:EntityDataSource ID="EquipmentEntityDataSource" runat="server" ConnectionString="name=ICTBillingEntities" DefaultContainerName="ICTBillingEntities" EnableDelete="True" EnableFlattening="False" EnableInsert="True" EnableUpdate="True" EntitySetName="tbEquipments" OnDeleted="EquipmentEntityDataSource_Command"
        OnInserted="EquipmentEntityDataSource_Command" OnUpdated="EquipmentEntityDataSource_Command"
        Where="(@EquipmentName is null || it.EquipmentName LIKE '%' + @EquipmentName + '%') AND (@EquipmentCode is null || it.EquipmentCode LIKE '%' + @EquipmentCode + '%')">
        <WhereParameters>
            <asp:ControlParameter ControlID="EquipmentNameTextBox" Name="EquipmentName" Type="String" />
            <asp:ControlParameter ControlID="EquipmentCodeTextBox" Name="EquipmentCode" Type="String" />
        </WhereParameters>
    </asp:EntityDataSource>
</asp:Content>

